package com.member.web.controller.shop;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.member.common.utils.StringUtils;
import com.member.shop.domain.ActivityFieldData;
import org.springframework.security.access.prepost.PreAuthorize;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import javax.annotation.Resource;

import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.enums.BusinessType;
import com.member.shop.domain.SysBizActivityField;
import com.member.shop.service.ISysBizActivityFieldService;
import com.member.common.utils.poi.ExcelUtil;
import com.member.common.core.page.TableDataInfo;
/**
 * 【活动报名字段】控制器
 *
 * @author wangxin
 * @version 1.0
 * @date 2024-06-14
 **/
@RestController
@RequestMapping("/shop/activityField")
public class SysBizActivityFieldController extends BaseController {
    @Resource
    private ISysBizActivityFieldService sysBizActivityFieldService;

    /**
     * 查询活动报名字段列表
     */
    @PreAuthorize("@ss.hasPermi('shop:activityField:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizActivityField sysBizActivityField) {
        startPage();
        LambdaQueryWrapper<SysBizActivityField> queryWrapper = new LambdaQueryWrapper<SysBizActivityField>();
        List<SysBizActivityField> list = sysBizActivityFieldService.selectSysBizActivityFieldList(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 查询活动报名字段列表
     */
    @PreAuthorize("@ss.hasPermi('shop:activityField:list')")
    @GetMapping("/list2")
    public AjaxResult list2(SysBizActivityField sysBizActivityField) {
        LambdaQueryWrapper<SysBizActivityField> queryWrapper = new LambdaQueryWrapper<SysBizActivityField>();
        List<SysBizActivityField> list = sysBizActivityFieldService.selectSysBizActivityFieldList(queryWrapper);
        return success(list);
    }

    /**
     * 导出活动报名字段列表
     */
    @PreAuthorize("@ss.hasPermi('shop:activityField:export')")
    @Log(title = "活动报名字段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizActivityField sysBizActivityField) {
        LambdaQueryWrapper<SysBizActivityField> queryWrapper = new LambdaQueryWrapper<SysBizActivityField>();
        List<SysBizActivityField> list = sysBizActivityFieldService.selectSysBizActivityFieldList(queryWrapper);
        ExcelUtil<SysBizActivityField> util = new ExcelUtil<SysBizActivityField>(SysBizActivityField. class);
        util.exportExcel(response, list, "活动报名字段数据");
    }

    /**
     * 获取活动报名字段详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:activityField:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizActivityFieldService.selectSysBizActivityFieldById(id));
    }

    /**
     * 新增活动报名字段
     */
    @PreAuthorize("@ss.hasPermi('shop:activityField:add')")
    @Log(title = "活动报名字段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizActivityField sysBizActivityField) {
        if (!CollectionUtils.isEmpty(sysBizActivityField.getFieldList())) {
            for (ActivityFieldData activityFieldData : sysBizActivityField.getFieldList()) {
                if (StringUtils.isBlank(activityFieldData.getName())) {
                    return error("字段名不能为空");
                }
            }
        }
        return toAjax(sysBizActivityFieldService.insertSysBizActivityField(sysBizActivityField));
    }

    /**
     * 修改活动报名字段
     */
    @PreAuthorize("@ss.hasPermi('shop:activityField:edit')")
    @Log(title = "活动报名字段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizActivityField sysBizActivityField) {
        if (!CollectionUtils.isEmpty(sysBizActivityField.getFieldList())) {
            for (ActivityFieldData activityFieldData : sysBizActivityField.getFieldList()) {
                if (StringUtils.isBlank(activityFieldData.getName())) {
                    return error("字段名不能为空");
                }
            }
        }
        return toAjax(sysBizActivityFieldService.updateSysBizActivityField(sysBizActivityField));
    }

    /**
     * 删除活动报名字段
     */
    @PreAuthorize("@ss.hasPermi('shop:activityField:remove')")
    @Log(title = "活动报名字段", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizActivityFieldService.deleteSysBizActivityFieldByIds(ids));
    }
}
